<?php
//导入 配置信息
include("config.php");



class ReqDataType{
	public $status='error';
	public $type='getMsg';
//	public $filename='';
	public $tableJson;
	public $tableType='NOT';
	public $msg;
}

class TableList{
	public $titlename;
	public $titleList;
	public $dataList;
	public $tag;
	public $choosename;
	public $chooselist;
}



class ProcTable{
	public $tableid;
	public $tableJson;
	public $tableList;
	public $reqDataType;
	public $conn;
	public $tag;
	public $type="";
	public $choosename="";
	public $chooselist=array();
	function Init($conn){
		$this->conn=$conn;
		$this->reqDataType=new ReqDataType();
	}
	
	function getTitleName($code){
		$sql="SELECT * FROM `tablelist` WHERE mask ='$code'";
		$conn=$this->conn;
		$result = $conn->query($sql);
		if($result->num_rows>0){
		//	查询 userid
			$row =$result->fetch_assoc();
		//	$_SESSION['userid']=$row['userid'];
		//	echo $row['tablejson'];
			$jsonobj=json_decode($row['tablejson']);
//			print_r($jsonobj);
			$this->tableid=$jsonobj->tableid;
			$this->tablejson=new StdClass();
			$this->tablejson->title=$row['title'];
			$this->tablejson->rowlist=$jsonobj->rowlist;
			$this->tablejson->rowlen=$jsonobj->len;
			$this->tag=$row['tag'];
			$this->tablejson->code=$code;
			$this->type=$row['type'];
//			echo json_encode($this->tablejson);
			$this->reqDataType->msg='get tableMsg success';
			$this->reqDataType->tableType=$this->type;
			
			 $this->reqDataType->status='success';
		}else{
			$this->reqDataType->msg='code error';
			$this->reqDataType->status='error';
		}
//		echo $this->tableid;
		return $this->tableid;
	}
	
	function getTableDatalist(){
		$listArray=array();
		$this->choosename=$this->tablejson->rowlist[0];
		$sql = "SELECT * FROM `I_tebles`.`".$this->tableid."`";
		$conn=$this->conn;
		$result = $conn->query($sql);
//		$chooselistTemp=array();
//		 echo $sql;
		if ($result->num_rows > 0) {
		    // 输出数据
//		    echo "{\"data\":[";
		    while($row = $result->fetch_assoc()) {
//		        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
				$listArray[]= $row;
				$this->chooselist[]=$row[$this->choosename];
				//$row[];
		    }
		    
		    $this->reqDataType->msg='get databody success';
		    $this->reqDataType->status='success';
//		    print_r($this->chooselist);
//		    $this->chooselist=$chooselistTemp;
//		print_r($this->tablejson);
		} else {
//		    echo "0 结果";
//			 ($this->tablejson);
			$this->reqDataType->msg='get databody error';
			$this->reqDataType->status='error';
		}
//		echo json_encode($listArray);
		$this->tablelist=$listArray;
		return ($this->tablelist);
//		echo "{}]}";
	}
}
//
////创建 处理 类
//$procTable=new ProcTable();
////回执信息 对象
//$reqData=new ReqDataType();
////数据表
//$tableList=new TableList();
//
//
////测试
//$code ='4ba6d674d604481dfecd7c217c436ef6';//not
////$code ='ebfeab83d18ef9198a2a7e36ce4e4105';//add
////$sql = "SELECT * FROM `tablelist` where mask= ";
////初始化 处理类  需要 数据库信息
//$procTable->Init($conn);
//
////获取 识别码
//$procTable->getTitleName($code);
////识别 处理表格的方式 
////添加 型的 则 使用 修改法 
//@$reqData=$procTable->reqDataType;
//if($procTable->type=='add'){
//	$tableList->titlename=$procTable->tablejson->title;
//	$tableList->titleList=$procTable->tablejson->rowlist;
//	$tableList->dataList=$procTable->getTableDatalist();
//	$tableList->choosename=$procTable->choosename;
//	$tableList->chooselist=$procTable->chooselist;
//	$reqData->tableJson=$tableList;
//	
//}else 
//// not 型的 使用  增加法显示
//if($procTable->type=='NOT'){
//	@$reqData->tableJson=($procTable->tablejson);
//}
//$reqData->tableType=$procTable->type;
//
////print_r($procTable);
//echo json_encode($reqData);
//$conn->close();

//@print_r($procTable);
?>